**********************************
* Informal Markets’ Adoption of Mobile Payment
* (Figures 3 & 4)
**********************************

* Figure 3 Informal Markets’ Adoption of Mobile Payment

use ${datafolder}/mobile_payment_provider_merchant_weekly_data, clear

gegen first_week = min(yearwk), by(mid)
format first_week %tw

keep if yearwk == first_week

gcontract yearwk
tsset yearwk
#delimit ;
tsline _freq if tin(2016w14,2017w39),
	ylabel(, glcolor(gs14) glpattern(dash) angle(horizontal)) ytitle("")  
	tlabel(2016w14(12)2017w39, format(%twMon_CCYY) labsize(small))  tline(2016w45)  ttitle("")
	graphregion(style(none) color(white) margin(zero) lstyle(none)) plotregion(margin(medium)) bgcolor(white)  
	name(entry_kirana, replace);
#delimit cr


* Figure 4: Digital Payment Transactions in Informal Markets

// This analysis only uses data on merchants who had already adopted the mobile payment four weeks prior to the Demonetization announcement
use ${datafolder}/mobile_payment_provider_merchant_weekly_data, clear
gegen first_week = min(yearwk), by(mid)
format first_week %tw
keep if first_week <= tw(2016w41)

keep if year(dofw(yearwk)) < 2018
gcollapse (sum) txn_count txn_amt, by(mid yearwk)
xtset mid yearwk
tsfill, full

replace txn_count = 0 if missing(txn_count)
replace txn_amt = 0 if missing(txn_amt)

gegen avg_txn_count = mean(txn_count), by(mid)
gen txn_count_demeaned = txn_count - avg_txn_count

gen byte has_txn = (txn_count > 0)


* Panel (a) Average weekly number of digital payment transactions across merchants
preserve
gcollapse txn_count, by(yearwk)
tsset yearwk
#delimit ;
tsline txn_count if tin(2016w14,2017w39), 
	ylabel(, glcolor(gs14) glpattern(dash) angle(horizontal)) ytitle("")  
	tlabel(2016w14(12)2017w39, format(%twMon_CCYY) labsize(small))  tline(2016w45)  ttitle("")
	graphregion(style(none) color(white) margin(zero) lstyle(none)) plotregion(margin(medium)) bgcolor(white)  
	name(avg_txn_count_kirana, replace);
#delimit cr
restore

* Panel (b) Average weekly amount of digital payment transactions across merchants
preserve
gcollapse txn_amt, by(yearwk)
tsset yearwk
#delimit ;
tsline txn_amt if tin(2016w14,2017w39), 
	ylabel(, format(%12.0fc) glcolor(gs14) glpattern(dash) angle(horizontal)) ytitle("")  
	tlabel(2016w14(12)2017w39, format(%twMon_CCYY) labsize(small))  tline(2016w45)  ttitle("")
	graphregion(style(none) color(white) margin(zero) lstyle(none)) plotregion(margin(medium)) bgcolor(white)  
	name(avg_txn_amount_kirana, replace);
#delimit cr
restore

* (c) Ratio of merchants with at least one digital payment transaction
preserve
gcollapse has_txn, by(yearwk)
tsset yearwk
#delimit ;
tsline has_txn if tin(2016w14,2017w39), 
	ylabel(0 "0%" 0.2 "20%" 0.4 "40%" 0.6 "60%" 0.8 "80%", 
		glcolor(gs14) glpattern(dash) angle(horizontal)) ytitle("")  
	tlabel(2016w14(12)2017w39, format(%twMon_CCYY) labsize(small))  tline(2016w45)  ttitle("")
	graphregion(style(none) color(white) margin(zero) lstyle(none)) plotregion(margin(medium)) bgcolor(white)  
	name(avg_has_txn_kirana, replace);
#delimit cr
restore
